package p.lodz.pl.poid.zad2.fourier;

public class ComplexNumber {

    public double real = 0;
    public double imaginary = 0;

    public ComplexNumber() {}

    public ComplexNumber(double real, double imaginary) {
        this.real = real;
        this.imaginary = imaginary;
    }
    
    public ComplexNumber(ComplexNumber z1){
        this.real = z1.real;
        this.imaginary = z1.imaginary;
    }
    
    public double getMagnitude(){
        return Math.sqrt(real*real + imaginary*imaginary);
    }
    
    public double getPhase(){
        return Math.atan2(imaginary,real);
    }
    
    public static ComplexNumber phaseModification(double theta) {
        ComplexNumber temp = new ComplexNumber(0, 0);
        temp.imaginary = Math.sin(theta);
        temp.real = Math.cos(theta);
        return temp;
    }
    
    public ComplexNumber multiply(ComplexNumber factor) {
        double re = this.real * factor.real - this.imaginary * factor.imaginary;
        double im = this.real * factor.imaginary + this.imaginary * factor.real;
        return new ComplexNumber(re, im);
    }
}